package hos.view;

import java.awt.BorderLayout;

import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import hos.dao.P_registerDaoImp;

public class PatientRigisterView {
	public PatientRigisterView(JFrame main) {
		// TODO Auto-generated constructor stub
		//窗口基础设置
		JFrame jf = new JFrame("患者挂号");
		jf.setVisible(true);
		jf.setSize(1000,800);
		jf.setLocationRelativeTo(main);
		jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		
		//panel容器设置
		SpringLayout spLayout = new SpringLayout();
		JPanel mainJPanel = new JPanel(spLayout);
		JPanel tableJPanel = new JPanel();
		JPanel tableHeadJPanel = new JPanel();
		JPanel labelJPanel = new JPanel();
		
		//表格设置
		//表头
		String[] columnName = {"科室编号","科室名","主任编号","科室电话","剩余病房"};
		P_registerDaoImp register = new P_registerDaoImp();
		String[][] rowData = register.selectDepart();
		
		// 创建一个表格，指定 所有行数据 和 表头
        JTable table = new JTable(rowData, columnName);
        
        //创建提示标签
        JLabel tipJLabel = new JLabel("请选择你要挂号的科室!");
        

        
        //位置及大小设置
        SpringLayout.Constraints tableCon = spLayout.getConstraints(tableJPanel);
        SpringLayout.Constraints tableHeadCon = spLayout.getConstraints(tableHeadJPanel);
        SpringLayout.Constraints labelCon = spLayout.getConstraints(labelJPanel);
        
        tableHeadCon.setX(Spring.constant(300));
        tableHeadCon.setY(Spring.constant(30));
        tableCon.setX(Spring.constant(300));
        tableCon.setY(tableHeadCon.getConstraint(SpringLayout.SOUTH));
        labelCon.setX(Spring.constant(0));
        labelCon.setY(Spring.constant(0));
        
        //添加到窗口上
        tableJPanel.add(table);
        tableHeadJPanel.add(table.getTableHeader());
        labelJPanel.add(tipJLabel);
        mainJPanel.add(tableJPanel);
        mainJPanel.add(tableHeadJPanel);
        mainJPanel.add(labelJPanel);
        jf.setContentPane(mainJPanel);
        
        //控制表格一次只能选择一行
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        
        //根据选择的行确定患者要挂的科室
        selectionModel.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				// TODO Auto-generated method stub
				//获取行数
				int selected = table.getSelectedRow();
				
			}
		});
        
        
	}
	
}
